1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Threading.Tasks;
9 using System.Windows.Forms;
10 using System.Data.SqlClient;
11
12 namespace MilkDairyManagementSystemCSharp
13 {
14 public partial class SetFatePrice : Form
15 {
16 public SetFatePrice()
17 {
18 InitializeComponent();
19 }
20
21 private void SetFatePrice_Load(object sender, EventArgs e)
22 {
23 // TODO: This line of code loads data into the 'milkdairyDataSet3.rate' table. You can move, or remove it, as needed.
24 this.rateTableAdapter.Fill(this.milkdairyDataSet3.rate);
25 using (SqlConnection con1 = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\dell\Documents\Visual Studio 2015\Projects\MilkDairyManagementSystemCSharp\MilkDairyManagementSystemCSharp\milkdairy.mdf;Integrated Security=True"))
26 {
27
28 string str2 = "SELECT * FROM rate";
29 SqlCommand cmd2 = new SqlCommand(str2, con1);
30 SqlDataAdapter da = new SqlDataAdapter(cmd2);
31 DataTable dt = new DataTable();
32 da.Fill(dt);
33
34 dataGridView1.DataSource = new BindingSource(dt, null);
35 }
36 SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\dell\Documents\Visual Studio 2015\Projects\MilkDairyManagementSystemCSharp\MilkDairyManagementSystemCSharp\milkdairy.mdf;Integrated Security=True");
37 con.Open();
38 string str1 = "select max(id) from rate;";
39
40 SqlCommand cmd1 = new SqlCommand(str1, con);
41 SqlDataReader dr = cmd1.ExecuteReader();
42 if (dr.Read())
43 {
44 string val = dr[0].ToString();
45 if (val == "")
46 {
47 textBox1.Text = "1";
48 }
49 else
50 {
51 int a;
52 a = Convert.ToInt32(dr[0].ToString());
53 a = a + 1;
54 textBox1.Text = a.ToString();
55 }
56 }
57 con.Close();
58 }
59
60 private void button1_Click(object sender, EventArgs e)
61 {
62 SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\dell\Documents\Visual Studio 2015\Projects\MilkDairyManagementSystemCSharp\MilkDairyManagementSystemCSharp\milkdairy.mdf;Integrated Security=True");
63 con.Open();
64 string gen = string.Empty;
65
66 try
67 {
68 string str = "INSERT INTO rate(c_fate_rate,n_fate_rate) VALUES('" + textBox2.Text + "','" + textBox3.Text + "'); ";
69
70 SqlCommand cmd = new SqlCommand(str, con);
71 cmd.ExecuteNonQuery();
72
73 string str1 = "select max(Id) from rate;";
74
75 SqlCommand cmd1 = new SqlCommand(str1, con);
76 SqlDataReader dr = cmd1.ExecuteReader();
77 if (dr.Read())
78 {
79 MessageBox.Show("Inserted Fate Rate Details Information Successfully..");
80 textBox2.Text = "";
81
82 textBox3.Text = "";
83 textBox1.Text = "";
84
85 using (SqlConnection con1 = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\dell\Documents\Visual Studio 2015\Projects\MilkDairyManagementSystemCSharp\MilkDairyManagementSystemCSharp\milkdairy.mdf;Integrated Security=True"))
86 {
87 string str2 = "SELECT * FROM rate";
88 SqlCommand cmd2 = new SqlCommand(str2, con1);
89 SqlDataAdapter da = new SqlDataAdapter(cmd2);
90 DataTable dt = new DataTable();
91 da.Fill(dt);
92 dataGridView1.DataSource = new BindingSource(dt, null);
93 }
94 }
95 }
96 catch (SqlException excep)
97 {
98 MessageBox.Show(excep.Message);
99 }
100 con.Close();
101 }
102
103 private void button2_Click(object sender, EventArgs e)
104 {
105 textBox2.Text = "";
106
107 textBox3.Text = "";
108 textBox1.Text = "";
109 }
110 }
111 }